package com.TCP_UDP网络编程.API_Method;

import java.net.InetAddress;
import java.net.UnknownHostException;
@SuppressWarnings("all")
public class InetAddress__网络地址 {  /// inet地址


    /// host == 主机   address == 地址
    public static void main(String[] args) throws UnknownHostException {
        /// 1.
        InetAddress localHost = InetAddress.getLocalHost();  ///用于获取本机的IP地址和电脑名称
        System.out.println(localHost);

        /// 2.根据设备名称，获取IP
        InetAddress host1 = InetAddress.getByName("wulubani");
        System.out.println(host1);

        /// 3.根据域名 返回InetAddress对象，输出www.baidu.com的IP
        InetAddress host2 = InetAddress.getByName("www.baidu.com");
        System.out.println(host2);

        /// 4.根据返回的InetAddress对象，反向获取主机名和IP地址
        System.out.println(host1.getHostName() + " " +host1.getHostAddress());

    }
}
